$(function() {
	// 兼容IE PlaceHolder
	$('input[type="text"],input[type="password"]').ASDPlaceHolder();
	
	// 点击删除继承对象，如top/inetOrgPerson等
	$('body').off();//解除绑定事件
	$('body').on('click', ".deleteLdapObject", function() {
		deleteLdapObject(this);
	});

	//初始化select2插件
	bindEventForSelect2();

	//删除xml配置参数
	$('body').on('click', ".deleteLdapParamsSpanClick", function() {
		deleteLdapDriverDataDetail(this);
	});
});

//初始化select2插件
function bindEventForSelect2() {
	$(".select-control").select2({
		width : "100%",
		theme : "classic",
		// Infinity展示的Option个数不限制
		minimumResultsForSearch : Infinity
	});
}

/**
 * 点击添加继承对象，如top/inetOrgPerson等
 * @param page 当前点击数据源或目标源区域对象
 * @returns top/inetOrgPerson等标签
 */
function addLdapObject(page) {
	var $html = $('<div class="input-group input-group-default">'
			+ '<input type="text" class="form-input form-input-default" name="extendObjects" maxlength="32" asd-valid="require" value=""/>'
			+ '<span class="fa fa-times-circle fastsyncer_pointer deleteLdapObject"></span>'
			+ '</div>');
	//添加object标签
	$(page).parents(".addLdapObjectContent").find("#addLdapObjectTextarea")
			.append($html).find(".form-input").focus();
}

/**
 * 点击删除继承对象，如top/inetOrgPerson等
 * @param type top/inetOrgPerson等标签
 * @returns
 */
function deleteLdapObject(type) {
	var obj = $(type).parents('.form-textarea').find('.input-group');
	if (obj.length == 1) {
		bootGrowl("继承对象不能为空", "danger");
		return;
	}
	$(type).parents('.input-group').remove();
}
/**
 * 添加ldap配置参数
 * @param page 当前点击数据源或目标源区域对象
 * @returns
 */
function addLdapDriverDataDetail(page) {
	var xmlDataHtml = $('<div class="form-group">'
			+ '<div class="col-sm-2"></div>'
			+ '<div class="col-sm-4">'
			+ '<input class="form-control" maxlength="32" asd-valid="require" type="text" name="filedName">'
			+ '</div>'
			+ '<div class="col-sm-4">'
			+ '<select class="form-control select-control" name="filedTypeName">'
			+ '<option value="12">VARCHAR</option>'
			+ '<option value="2">NUMERIC</option>'
			+ '<option value="4">INTEGER</option>'
			+ '<option value="91">DATE</option>'
			+ '<option value="93">TIMESTAMP</option>'
			+ '<option value="6">FLOAT</option>'
			+ '<option value="8">DOUBLE</option>'
			+ '<option value="-1">LONGVARCHAR</option>'
			+ '</select>'
			+ '</div>'
			+ '<span class="fa fa-minus fa-2x fastsyncer_pointer col-sm-2 form-control-static deleteLdapParamsSpanClick"></span>'
			+ '</div>');
	$(page).parents(".driverLdapParamsContainer").append(xmlDataHtml);

	//初始化select2插件
	bindEventForSelect2();
}

/**
 * 删除ldap配置参数
 * @param type 当前字段
 * @returns
 */
function deleteLdapDriverDataDetail(type) {
	$(type).parents('.form-group').remove();
}